@page "/role"
@using BootBlazor.Servers.Auth
@using BootBlazor.Servers.Components.Pages
@using BootBlazor.Servers.Helper
@using BootBlazor.Servers.Data
@using BootBlazor.Servers.Services

@rendermode RenderMode.InteractiveServer
@attribute [StreamRendering]

<PageHeader Title="@Loc["RolePage_Title"]">
    <MudGrid Class="justify-end">
        <MudItem>
            <MudTextField T="string" @bind-Value="searchObject.SearchText" Margin="Margin.Dense" Class="search-com"
                          Label="@Loc["RolePage_SearchKeywordPlaceholder"]" Variant="Variant.Outlined"></MudTextField>
        </MudItem>
        <MudItem>
            <MudIconButton Size="MudBlazor.Size.Medium" Icon="@Icons.Material.Filled.Search" OnClick="() => dataGridRef.ReloadServerData()"
                           Variant="Variant.Outlined" Color="Color.Primary" Class="mr-2"></MudIconButton>
            <MudTooltip Text="重置搜索" Color="Color.Primary">
                <MudIconButton Size="MudBlazor.Size.Medium" Icon="@Icons.Material.Filled.SearchOff" OnClick="SearchReset"
                               Variant="Variant.Outlined" Color="Color.Primary" Class="mr-2"></MudIconButton>
            </MudTooltip>
            @if (_accessService.CheckHasElementRights("RoleAddBtn").Result)
            {
                <MudIconButton Size="MudBlazor.Size.Medium" Icon="@Icons.Material.Filled.Add" OnClick="AddRoleClick"
                               Variant="Variant.Outlined" Color="Color.Primary" Class=""></MudIconButton>
            }
        </MudItem>
    </MudGrid>
</PageHeader>

<MudDataGrid Dense=PageDataGridConfig.Dense Filterable=PageDataGridConfig.Filterable ColumnResizeMode=PageDataGridConfig.ColumnResizeMode
             SortMode=PageDataGridConfig.SortMode Groupable=PageDataGridConfig.Groupable Virtualize=PageDataGridConfig.Virtualize
             FixedHeader=PageDataGridConfig.FixedHeader Elevation=PageDataGridConfig.Elevation Outlined=PageDataGridConfig.Outlined
             Style="@PageDataGridConfig.Style" HorizontalScrollbar="PageDataGridConfig.HorizontalScrollbar"
             SelectedItems="selectedItems" ServerData="GetTableData" @ref="dataGridRef" T="RoleModel">
    <Columns>
        <SelectColumn T="RoleModel" ShowInFooter="false" />
        <PropertyColumn Title="@Loc["RolePage_TableH1"]" Property="x=>x.Number" HeaderStyle="white-space:nowrap;width:40px;" Resizable="false" />
        <PropertyColumn Title="@Loc["RolePage_TableH2"]" Property="x=>x.Name" HeaderStyle="white-space:nowrap;" />
        <TemplateColumn Title="@Loc["RolePage_TableH3"]" HeaderStyle="white-space:nowrap">
            <CellTemplate>
                <MudSwitch Value="@context.Item.IsEnabled" T="bool" Disabled="@(!_accessService.CheckHasElementRights("RoleActiveBtn").Result)"
                           ValueChanged="v=>ChangeRoleActive(context.Item.Id,v)" Color="Color.Primary">
                </MudSwitch>
            </CellTemplate>
        </TemplateColumn>
        <TemplateColumn Title="@Loc["RolePage_TableH4"]" HeaderStyle="white-space:nowrap;width:150px;" StickyRight="true" Resizable="false">
            <CellTemplate>
                <MudStack Row Spacing="1">
                    @if (_accessService.CheckHasElementRights("RoleDeleteBtn").Result)
                    {
                        <MudIconButton Size="@MudBlazor.Size.Small" Class="pa-2" Icon="@Icons.Material.Outlined.Delete" Color="Color.Error"
                                       OnClick="()=>DeleteRoleClick(context.Item.Id)" />
                    }
                    @if (_accessService.CheckHasElementRights("RoleUpdateBtn").Result)
                    {
                        <MudIconButton Size="@MudBlazor.Size.Small" Class="pa-2" Icon="@Icons.Material.Outlined.Edit" Color="Color.Primary"
                                       OnClick="()=>EditRoleClick(context.Item.Id)" />
                    }
                    @if (_accessService.CheckHasElementRights("RoleMenuBtn").Result)
                    {
                        <MudIconButton Size="@MudBlazor.Size.Small" Class="pa-2" Icon="@Icons.Material.Outlined.Menu" Color="Color.Tertiary"
                                       OnClick="()=>SetRoleMenuClick(context.Item.Id)" />
                    }
                </MudStack>
            </CellTemplate>
        </TemplateColumn>
    </Columns>
</MudDataGrid>

<PagePagination PageInfo="searchObject" PageChangedClick="PageChangedClick"></PagePagination>
